﻿using NetSurveillance.WebApp.DataServices.Models;
using ServiceStack.OrmLite;

namespace NetSurveillance.WebApp.DataServices.Implementations
{
    public class ServerStatusService : BaseService<ServerStatus>
    {
        public ServerStatusService(string connStr, IOrmLiteDialectProvider provider = null)
            : base(connStr, provider)
        {
        }

        public ServerStatus GetLastServerStatus()
        {
            using (var db = DbFactory.OpenDbConnection())
            {
                const string searchSql =
                    @"select * from ""ServerStatus"" where ""StatusToken"" != 0 order by ""Id"" desc limit 1";
                var serverStatus = db.QuerySingle<ServerStatus>(searchSql, null);
                return serverStatus;
            }
        }
    }
}